package com.pureut.production.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.production.domain.RollPackingHistory;
import com.pureut.production.domain.dto.RollPackingDto;
import com.pureut.production.domain.vo.*;
import com.pureut.production.service.RollPackingHistoryService;
import com.pureut.production.service.RollPackingService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/***
 * 小卷打包控制层
 * Author:C
 * Date:2023/02/22 11:56
 * @DESC
 */
@RestController
@RequestMapping("/roll-packing")
public class RollPackingController extends BaseController {

    @Resource
    RollPackingService rollPackingService;

    /**
     * 小卷历史表
     */
    @Resource
    RollPackingHistoryService rollPackingHistoryService;


    /**
     * 小卷打包列表
     */
    @RequiresPermissions("productionTube:produAdm:slitting:rollshop:list")
    @GetMapping("/list")
    public TableDataInfo getList(RollPackingVo rollPackingVo) {
        startPage();
        List<RollPackingDto> list;
        if (rollPackingVo.getType() == 1) {
            //查自己
            list = rollPackingService.getList(rollPackingVo);
        }else {
            //查全部
            list = rollPackingService.getAllList(rollPackingVo);
        }
        return getDataTable(list);
    }

    /**
     * 勾选打包
     */
    @RequiresPermissions("productionTube:produAdm:slitting:rollshop:tick")
    @GetMapping("/view/{ids}")
    public AjaxResult getViewById(@PathVariable("ids") String ids) {
        return AjaxResult.success(rollPackingService.getViewById(ids));
    }

    /**
     * 修改勾选数据打印状态
     */
    @PutMapping("/updateStatus")
    @Log(title = "修改勾选数据打印状态", businessType = BusinessType.UPDATE)
    public AjaxResult updateStatus(@RequestBody IdsVo idsVo) {
        return toAjax(rollPackingService.updateStatus(idsVo));
    }


    /**
     * 小卷不良
     */
    @RequiresPermissions("productionTube:produAdm:slitting:rollshop:bad")
    @GetMapping("/badSmallRoll/{id}")
    @Log(title = "小卷不良", businessType = BusinessType.INSERT)
    public AjaxResult badSmallRoll(@PathVariable("id") Long id) {
        return toAjax(rollPackingService.badSmallRoll(id));
    }

    /**
     * 补打标签
     */
    @RequiresPermissions("productionTube:produAdm:slitting:rollshop:patchwork")
    @GetMapping("/retag/{id}")
    public AjaxResult retag(@PathVariable("id") Long id) {
        return AjaxResult.success(rollPackingService.retag(id));
    }

    /**
     * 修改接头
     *
     * @return
     */
    @RequiresPermissions("productionTube:produAdm:slitting:rollshop:edit")
    @PutMapping("/updateJoint")
    @Log(title = "修改接头", businessType = BusinessType.UPDATE)
    public AjaxResult updateJoint(@RequestBody JointVo jointVo) {
        return toAjax(rollPackingService.updateJoint(jointVo));
    }

    /**
     * 修改接头回显
     */
    @GetMapping("/jointView/{ids}")
    public AjaxResult jointView(@PathVariable("ids") String ids) {
        return AjaxResult.success(rollPackingService.jointView(ids));
    }

    /**
     * 打包标签
     */
    @RequiresPermissions("productionTube:produAdm:slitting:rollshop:packageLabel")
    @PostMapping("/packageLabel")
    @Log(title = "打包标签", businessType = BusinessType.INSERT)
    public AjaxResult packageLabel(@RequestBody PackageLabelVo packageLabelVo) throws Exception {
        return AjaxResult.success(rollPackingService.packageLabel(packageLabelVo));
    }

    /**
     * 查询小卷关联的母卷（远程调用 产品追溯）
     */
    @GetMapping("/selectMasterVolumeNumberList")
    public AjaxResult selectMasterVolumeNumberList(String masterVolumeNumber) {
        return AjaxResult.success(rollPackingService.selectMasterVolumeNumberList(masterVolumeNumber));
    }

    /**
     * 根据小卷号码查询小卷信息
     * （远程调用 产品追溯）
     */
    @GetMapping("/getTraceabilityRollInfo")
    public AjaxResult getTraceabilityRollInfo(String materialNumber) {
        return AjaxResult.success(rollPackingService.getTraceabilityRollInfo(materialNumber));
    }

    /**
     *  根据小卷号码查询小卷历史表信息
     * （远程调用 产品追溯）
     */
    @GetMapping("/selectRollPackingHistoryInfo")
    public AjaxResult selectRollPackingHistoryInfo(String smallVolumeNumber) {
        return AjaxResult.success(rollPackingHistoryService.selectRollPackingHistoryInfo(smallVolumeNumber));
    }

    /**
     *  根据母卷号码查询小卷历史表信息
     * （远程调用 产品追溯）
     */
    @GetMapping("/selectRollPackingHistoryMasterVolumeNumber")
    public AjaxResult selectRollPackingHistoryMasterVolumeNumber(String masterVolumeNumber) {
        return AjaxResult.success(rollPackingHistoryService.selectRollPackingHistoryMasterVolumeNumber(masterVolumeNumber));
    }
}
